<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Course;
use Illuminate\Http\Request;

class CourseController extends Controller {


    //列表
    public function index(){
        $lists = Course::getList();
        return $this->writeJson(0,$lists);
    }


    //更新
    public function update(Request $request)
    {
        $data = $request->all();
        if($data['id']){
            $info = Course::findOrFail($data['id']);
            $info->update($data);
            return $this->writeJson(0,null,'修改历程信息成功');
        }else{
            unset($data['id']);
            Course::create($data);
            return $this->writeJson(0,null,'新增历程信息成功');
        }
    }


    //删除
    public function destroy(Request $request){
        $id = (int)$request->get('id',0);
        if(empty($id)){
            return $this->writeJson(1,null,'参数错误');
        }
        Course::destroy($id);
        return $this->writeJson(0);
    }

}
